<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    *{
      margin: 0;
      padding: 0;
    }
    .box{
      width: 300px;
      height: 300px;
      border: 1px solid #ccc;
      cursor:move;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translateX(-50%) translateY(-50%); 
    }
    .line{
      width: 100%;
      height: 40px;
      background-color: rgb(55, 156, 214);
      line-height: 40px;
      padding-left: 10px;
      box-sizing: border-box;
    }
    span:nth-child(1){
      font-weight: 600;
    }
    span:nth-child(2){
      color: white;
      float: right;
      padding-right: 10px;
      cursor:pointer;
    }
  </style>
</head>
<body>
  <div class="box">
    <div class="line">
      <span>用户注册信息</span>
      <span class="close">关闭</span>
    </div>
  </div>
  <script>
    var box = document.querySelector('.box');
    var close = document.querySelector('.close');
    box.onmousedown = function(e){
      var mouse_x = e.clientX - this.offsetLeft;
      var mouse_y = e.clientY - this.offsetTop;
      document.onmousemove = function(e){
        box.style.left = e.clientX - mouse_x + 'px';
        box.style.top = e.clientY - mouse_y  + 'px';
      };
    };
    box.onmouseup = function(){
      document.onmousemove = null;
    };
    close.onclick = function(){
      var flag = confirm('确定要关闭么')
      if(flag == true){
        box.style.display = 'none';
      }else{
        box.style.display = 'block';
      };
    };
  </script>
</body>
</html>